#-*-encoding=utf-8-*-

@script_attr(permission='zope.Public',use_template='basic')
def index():
    """首 页

    这是应用的首页"""
    print '<h1>最近更新</h1> '
    print '<p> 下面是最新的通知公告、学校文档资料，以及个人文档，详细请查看各个栏目 </p>'

    print '<h3>最新公共通知</h3>'
    results = searchObjects(path = root['forum'],
                            sort_index='modified',
                            reverse=True,
                            limit=5, 
                  restricted=False, )

    print '<ul>'
    for obj in results:
        print '<li><a href="%s">' % absoluteURL(obj,request)
        print IDublinCore(obj).title, '</a>'
        print org_info.getPrincipalInfo(IDublinCore(obj).creators[0])['title']
        print getDisplayTime(IDublinCore(obj).modified), '</li>'
    print '</ul>'

    print '<h3>最新学校文档</h3>'
    results = searchObjects(path = [root['files'], root['yuanji'], root['jiguan'], root['jiaoxue'], root['jiaofu']],
                            sort_index='modified',
                            reverse=True,
                            limit=10, 
                  restricted=False, )
    print '<ul>'
    for obj in results:
        print '<li><a href="%s/@@view.html">' % absoluteURL(obj,request)
        print IDublinCore(obj).title, '</a>'
        print org_info.getPrincipalInfo(IDublinCore(obj).creators[0])['title']
        print getDisplayTime(IDublinCore(obj).modified), '</li>'
    print '</ul>'


    print '<h3>最新个人文档</h3>'
    results = searchObjects(path = root['desks'],
                            sort_index='modified',
                            reverse=True,
                            limit=5, 
                  restricted=False, )
    print '<ul>'
    for obj in results:
        print '<li><a href="%s/@@view.html">' % absoluteURL(obj,request)
        print IDublinCore(obj).title, '</a>'
        print org_info.getPrincipalInfo(IDublinCore(obj).creators[0])['title']
        print getDisplayTime(IDublinCore(obj).modified), '</li>'
    print '</ul>'

    return printed

@script_attr(permission='zope.Public',use_template='blank')
def setup():
    """install

installer"""
    IDublinCore(root).title = u'学校教学评估系统'
    IAppletData(root).tab_style = u'tab'

    deployApplet('zopen.edu', context, u'index', u'首 页')
    forum = deployApplet('default.forum', context, u'forum', u'公告通知')
    forum.addCategory('upper', u'上级公告')
    forum.addCategory('school', u'学校公告')
    forum.addCategory('notice', u'系统通知')
    forum.addCategory('help', u'系统帮助')

    # 文件： 默认所有人都可以查看文件，在temp文件夹可添加
    files = deployApplet('default.filerepos', context, u'files', u'文档资源')
    IGrantManager(files).grantRole('zopen.Reader4', 'groups.tree.default')


    folder = files.addFolder(u'党委办公室')
    folder = files.addFolder(u'组织人事部') 
    folder = files.addFolder(u'纪委监察部') 
    folder = files.addFolder(u'教务处') 
    folder = files.addFolder(u'学校办公室') 
    folder = files.addFolder(u'计划财务处') 
    folder = files.addFolder(u'后勤保障处') 
    folder = files.addFolder(u'团学工作部') 
    folder = files.addFolder(u'工会离退休工作处') 
    folder = files.addFolder(u'科技处') 
    folder = files.addFolder(u'中文系') 
    folder = files.addFolder(u'外文系') 
    folder = files.addFolder(u'数学系') 
    folder = files.addFolder(u'物电系') 
    folder = files.addFolder(u'化生系') 
    folder = files.addFolder(u'地旅系') 
    folder = files.addFolder(u'计科系') 
    folder = files.addFolder(u'经管系') 
    folder = files.addFolder(u'艺术系') 
    folder = files.addFolder(u'体育系') 
    folder = files.addFolder(u'两课部') 
    folder = files.addFolder(u'信息管理中心') 
    folder = files.addFolder(u'学报') 
    folder = files.addFolder(u'图书馆') 

    folder = files.addFolder(u'temp', u'临时区',u'此文件夹禁止删除，用于存放附件或者其他临时文件')
    IGrantManager(folder).grantRole('zopen.Reader4', 'groups.tree.default')
    IGrantManager(folder).grantRole('zopen.Collaborator', 'groups.tree.default')

    folder = files['temp'].addFolder(u'scan', u'扫描临时区', u'扫描的临时共享区域，扫描文件默认存放在这里')
    IGrantManager(folder).grantRole('zopen.Editor', 'groups.tree.default')

    files = deployApplet('default.filerepos', context, u'yuanji', u'院级文档')
    IGrantManager(files).grantRole('zopen.Reader4', 'groups.tree.default')

    files = deployApplet('default.filerepos', context, u'jiguan', u'机关文档')
    IGrantManager(files).grantRole('zopen.Reader4', 'groups.tree.default')

    files = deployApplet('default.filerepos', context, u'jiaoxue', u'教学文档')
    IGrantManager(files).grantRole('zopen.Reader4', 'groups.tree.default')

    files = deployApplet('default.filerepos', context, u'jiaofu', u'教辅文档')
    IGrantManager(files).grantRole('zopen.Reader4', 'groups.tree.default')

